package Solutions;

public class Solution12 {
    public static void main(String[] args) {
        Solution012 solution012=new Solution012();
        int[][] matrix=new int[][]{{1,1,1},{1,0,1},{1,1,1}};
        solution012.setZeroes(matrix);
    }

}
class Solution012 {
    public void setZeroes(int[][] matrix) {
        int m = matrix.length, n = matrix[0].length;
        // 标记行和列是否需要置零
        boolean[] row = new boolean[m];
        boolean[] col = new boolean[n];
        // 遍历矩阵，标记需要置零的行和列
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                //找到0
                if (matrix[i][j] == 0) {
                    //标记行和列
                    row[i] = col[j] = true;
                }
            }
        }
        // 再次遍历矩阵，置零
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (row[i] || col[j]) {
                    matrix[i][j] = 0;
                }
            }
        }
    }
}